﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <sys:Double x:Key="CloseButtonWidthAndHeight">14</sys:Double>
    <Color x:Key="TabItem_ForegroundColor_Base">#4971A3</Color>

    <SolidColorBrush x:Key="TabItemCloseButtonNormalForegroundBrush"
                     Color="{StaticResource TabItem_ForegroundColor_Base}" />
    <SolidColorBrush x:Key="TabItemCloseButtonHoverForegroundBrush"
                     Color="White" />
    <SolidColorBrush x:Key="TabItemCloseButtonPressedForegroundBrush"
                     Color="#EEEE" />
    <LinearGradientBrush x:Key="TabItemCloseButtonNormalBackgroundBrush"
                         StartPoint="0,0"
                         EndPoint="1,0">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#5FFF"
                              Offset="0.0" />
                <GradientStop Color="#5CCC"
                              Offset="1.0" />
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="TabItemCloseButtonNormalBorderBrush"
                         StartPoint="0,0"
                         EndPoint="1,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#5CCC"
                              Offset="0.0" />
                <GradientStop Color="#5444"
                              Offset="1.0" />
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="TabItemCloseButtonHoverBackgroundBrush"
                         StartPoint="0,1"
                         EndPoint="1,0">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FFDF2B1E"
                              Offset="0.0" />
                <GradientStop Color="#FFA41F00"
                              Offset="1.0" />
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="TabItemCloseButtonPressedBackgroundBrush"
                         StartPoint="0,0"
                         EndPoint="1,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FFA41F00"
                              Offset="0.0" />
                <GradientStop Color="#FFDF2B1E"
                              Offset="1.0" />
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="TabItemCloseButtonPressedBorderBrush"
                         StartPoint="0,0"
                         EndPoint="1,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#5444"
                              Offset="0.0" />
                <GradientStop Color="#5CCC"
                              Offset="1.0" />
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <Geometry x:Key="X_CloseButton">M0,0 L10,10 M0,10 L10,0</Geometry>

    <Style x:Key="TabItemCloseButtonStyle"
           TargetType="{x:Type Button}">
        <!-- 
            The default value for SnapsToDevicePixels actually is False
            (so this setter really wouldn't be required). However, I'm 
            adding this nevertheless in order to explicitly point out that,
            in this case, it is required (see below).
         -->
        <Setter Property="SnapsToDevicePixels"
                Value="false" />
        <Setter Property="Height"
                Value="{StaticResource CloseButtonWidthAndHeight}" />
        <Setter Property="Width"
                Value="{StaticResource CloseButtonWidthAndHeight}" />
        <Setter Property="Cursor"
                Value="Hand" />
        <Setter Property="Focusable"
                Value="False" />
        <Setter Property="OverridesDefaultStyle"
                Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border x:Name="ButtonBorder"
                            CornerRadius="2"
                            BorderThickness="1"
                            Background="{StaticResource TabItemCloseButtonNormalBackgroundBrush}"
                            BorderBrush="{StaticResource TabItemCloseButtonNormalBorderBrush}">
                        <Grid>
                            <!-- The Path below will render the button's X. -->
                            <Path x:Name="ButtonPath"
                                  Margin="2"
                                  Data="{StaticResource X_CloseButton}"
                                  Stroke="{StaticResource TabItemCloseButtonNormalForegroundBrush}"
                                  StrokeThickness="2"
                                  StrokeStartLineCap="Round"
                                  StrokeEndLineCap="Round"
                                  Stretch="Uniform"
                                  VerticalAlignment="Center"
                                  HorizontalAlignment="Center" />
                            <!-- We don't really need the ContentPresenter, but what the heck ... -->
                            <ContentPresenter HorizontalAlignment="Center"
                                              VerticalAlignment="Center" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter TargetName="ButtonBorder"
                                    Property="Background"
                                    Value="{StaticResource TabItemCloseButtonHoverBackgroundBrush}" />
                            <Setter TargetName="ButtonPath"
                                    Property="Stroke"
                                    Value="{StaticResource TabItemCloseButtonHoverForegroundBrush}" />
                        </Trigger>
                        <Trigger Property="IsEnabled"
                                 Value="false">
                            <Setter Property="Visibility"
                                    Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="IsPressed"
                                 Value="true">
                            <Setter TargetName="ButtonBorder"
                                    Property="Background"
                                    Value="{StaticResource TabItemCloseButtonPressedBackgroundBrush}" />
                            <Setter TargetName="ButtonBorder"
                                    Property="BorderBrush"
                                    Value="{StaticResource TabItemCloseButtonPressedBorderBrush}" />
                            <Setter TargetName="ButtonPath"
                                    Property="Stroke"
                                    Value="{StaticResource TabItemCloseButtonPressedForegroundBrush}" />
                            <!-- 
                           Simulate a pressed-effect by moving the contents down and to the right.
                           Since the button is pretty small, the trick here is to only shift things
                           just a tiny little bit, hence the fractional values below.
                           Note that, in order for this to work as expected, SnapsToDevicePixels
                           must be set to "false" (see the setter at the top of this style).
                        -->
                            <Setter TargetName="ButtonPath"
                                    Property="Margin"
                                    Value="2.5,2.5,1.5,1.5" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>